/*
 * RegistroFrases.cpp
 *
 *  Created on: Oct 7, 2012
 *      Author: romina
 */

#include "RecordFrase.h"

RecordFrase::RecordFrase(){
	this->id = -1;
	this->autor = new Autor("nn", "nn");
	this->frase = new Frase("----");
}

RecordFrase::RecordFrase(int id, string apellido, string nombre, string frase){
	this->id = id;
	this->autor = new Autor(apellido, nombre);
	this->frase = new Frase(frase);
}

RecordFrase::RecordFrase(int id, Autor * autor, Frase * frase){
	this->id = id;
	this->autor = autor;
	this->frase = frase;
}

int RecordFrase::getId(){
	return this->id;
}

Autor * RecordFrase::getAutor(){
	return this->autor;
}

Frase * RecordFrase::getFrase(){
	return this->frase;
}

int RecordFrase::getTamanio(){
	return (4*sizeof(int) + this->autor->getTamanio() + this->frase->getTamanio() );
}

void RecordFrase::setAutor(Autor * autor){
	this->autor = autor;
}

void RecordFrase::setFrase(Frase * frase){
	this->frase = frase;
}

int RecordFrase::getLongitud(){
	return this->toString().length();
}

string RecordFrase::toString(){
	string id = Palabra::intToString(this->id);
	string autor = this->autor->toString();
	string frase = this->frase->toString();

	return id + '|' + autor + '|' + frase;
}

void RecordFrase::show(){
	cout << "ID: " << id << endl;
	cout << "Apellido: " << autor->getApellido() << endl;
	cout << "Nombre: " << autor->getNombre() << endl;
	cout << "Frase: " << frase->toString() << endl;
}

void RecordFrase::serializar(char * buffer, unsigned int &offset){

	PersistorHASH::transformar_entero_en_char(buffer, offset, this->id);
	this->autor->serializar(buffer, offset);
	this->frase->serializar(buffer, offset);
}

void RecordFrase::deserializar(char * buffer, unsigned int &offset){

	this->id = PersistorHASH::obtener_entero_desde_Buffer(buffer, offset);
	this->autor->deserializar(buffer, offset);
	this->frase->deserializar(buffer, offset);
}

RecordFrase::~RecordFrase(){

}




